import $ from "jquery"

import RecodeUtil from "./recode"
import { sleep, transFromSeconds, triggerMouseEvent } from "./util"

class Grapper {
  /**
   * 获取当前问诊类型
   */
  static getCurrentType() {
    const title = $("#consultType")
      .closest(".ant-select-selector")
      .find(".ant-select-selection-item")
      .attr("title")
    if (title && title.includes("先方")) {
      return title === "先方" ? 1 : 2
    } else {
      return 0
    }
  }
  /**
   * 获取当前页的订单信息
   */
  static getCurrentPageInfo() {
    const tableRows = $(".ant-table-container  .ant-table-tbody")
      .eq(0)
      .find(".ant-table-row")

    const orderList = []

    tableRows.each((index, row) => {
      let order = []

      // '问诊开始时间', '医生名', '用户ID', '问诊结束时间', '问诊时长', '会话ID', '医生ID', '机构名称', '满意度', '问诊类型'
      for (let i = 0; i < row.children.length; i++) {
        const tmp = (row.children[i].innerText || "").trim()
        order.push(tmp)
      }
      const orderInfo = {
        inquiryStartTime: order[0],
        doctorName: order[1],
        doctorId: order[6],
        inquiryEndTime: order[3],
        inquiryConsumeTime: transFromSeconds(order[4] || "--"),
        sessionId: order[5],
        userId: order[2],
        institutionName: order[7],
        satisfactionLevel: order[8],
        inquiryType: order[9]
      }
      orderList.push(orderInfo)
    })

    return orderList
  }
}

export default Grapper
